package com.carreirati.evaluation;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import com.carreirati.evaluation.domain.UserLogin;
import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("/userlogins")
@Controller
@RooWebScaffold(path = "userlogins", formBackingObject = UserLogin.class)
@RooWebJson(jsonObject = UserLogin.class)
public class UserLoginController {

	   @RequestMapping(method = RequestMethod.POST, produces = "text/html")
	    public String create(@Valid UserLogin userLogin, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
	        if (bindingResult.hasErrors()) {
	            populateEditForm(uiModel, userLogin);
	            return "userlogins/create";
	        }
	        uiModel.asMap().clear();
	        userLogin.persist();
	        userLogin = UserLogin.findUserLogin(userLogin.getUsers().getId());
	        return "redirect:/userlogins/" + encodeUrlPathSegment(userLogin.getUserId().toString(), httpServletRequest);
	    }
	

}
